
package com.ksvip.next.components.datasecure.logback;

import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import lombok.Getter;
import lombok.Setter;

/**
 * 异常堆栈敏感信息数据转换器
 *
 * @author chenyao
 * @since 2019年5月14日 上午11:49:42
 */
@Setter
@Getter
public class SensitiveDataThrowableProxyConverter extends ThrowableProxyConverter {

    @Override
    public String convert(ILoggingEvent event) {
        String formattedMessage = super.convert(event);
        //基本脱敏key构造
        SensitiveDataKeysBuilder.checkAndSetSensitiveDataRules(this.getContext());
        // 获取脱敏后的日志
        return SensitiveDataConverter.filterMessage(SensitiveDataKeysBuilder.getSensitiveDataAllowRun(),
                SensitiveDataKeysBuilder.getSensitiveDataRules(), formattedMessage);
    }
}
